import xlrd
import xlwt



class AutoMaic():

    data=""
    writerow=1
    def excelExcult(self):
        # 设置自动换行
        style = xlwt.XFStyle()
        style.alignment.wrap = 1
        workbook = xlwt.Workbook(encoding=ascii)
        worksheet = workbook.add_sheet('测试用例')

        # 创建居中对齐格式
        alignment = xlwt.Alignment()
        alignment.horz = 0x02
        alignment.vert = 0x01


        # 创建标题
        self.createTitle(worksheet)
        with open("autoceshi.txt", "r", encoding="utf-8") as f:  # 打开文件
            self.data = f.readlines()
        # 循环执行接口中的数据
        for i in self.data:
            # 测试用例1
            worksheet.write(self.writerow,0,"")
            worksheet.write(self.writerow, 1,"接口管理")
            worksheet.write(self.writerow,2,"验证"+i+"在接口管理中是否正常显示")
            worksheet.write(self.writerow, 3, "")
            worksheet.write(self.writerow, 4, "1.进入接口管理 2.搜索"+i+"接口 3.查看列表 4.点击详情查看出参/入参")
            worksheet.write(self.writerow, 5, i+"出参入参正常显示，且列表显示对应接口")
            worksheet.write(self.writerow, 6,"")
            worksheet.write(self.writerow, 7,"通过")
            worksheet.write(self.writerow, 8, "功能测试")

            # 测试用例2
            worksheet.write(self.writerow+1,0,"")
            worksheet.write(self.writerow+1,1,"三方数据源")
            worksheet.write(self.writerow+1,2,"验证"+i+"是否正常对接")
            worksheet.write(self.writerow+1, 3, "准备测试账号以及"+i+"相关调用请求参数")
            worksheet.write(self.writerow+1, 4, "1.进入接口管理 2.选择"+i+"接口 3.通过测试API调用 4.查看结果返回")
            worksheet.write(self.writerow+1, 5, i+"接口正常调用且返回")
            worksheet.write(self.writerow+1, 6,"")
            worksheet.write(self.writerow+1, 7,"通过")
            worksheet.write(self.writerow+1, 8, "接口测试")


            # 测试用例2
            worksheet.write(self.writerow+2,0,"")
            worksheet.write(self.writerow+2,1,"变量中心")
            worksheet.write(self.writerow+2,2,"验证"+i+"是否在变量中引用是否正常")
            worksheet.write(self.writerow+2, 3, "")
            worksheet.write(self.writerow+2, 4, "1.进入变量中心 2.选择"+i+"接口 3.设计变量相关逻辑 4.点击变量测试")
            worksheet.write(self.writerow+2, 5, i+"接口正常调用且返回变量中引用的相关字段")
            worksheet.write(self.writerow+2, 6,"")
            worksheet.write(self.writerow+2, 7,"通过")
            worksheet.write(self.writerow+2, 8, "功能测试")


            # 测试用例3
            worksheet.write(self.writerow+3,0,"")
            worksheet.write(self.writerow+3,1,"决策流管理")
            worksheet.write(self.writerow+3,2,"验证"+i+"是否在决策流引用正常")
            worksheet.write(self.writerow+3, 3, "设计好决策流且引用该接口的相关变量")
            worksheet.write(self.writerow+3, 4, "1.进入决策流管理 2.执行决策流 3.查看决策流执行结果 ")
            worksheet.write(self.writerow+3, 5, "引用"+i+"接口的决策流正常调用")
            worksheet.write(self.writerow+3, 6,"")
            worksheet.write(self.writerow+3, 7,"通过")
            worksheet.write(self.writerow+3, 8, "功能测试")


            self.writerow=self.writerow+4

        workbook.save("C:\\Users\\A\\Desktop\\2023-01-15交付文档\\决策引擎\\2022-05-20  集奥bug线上缺陷修复\\测试用例\\集奥-测试用例.xls")

    def createTitle(self,worksheet):
        # 首行冻结
        worksheet.set_panes_frozen('1')
        # 水平冻结
        worksheet.set_horz_split_pos(1)
        first_col = worksheet.col(0)
        first_col.width = 256 * 20

        #首行字体


        worksheet.write(0,0,"编号")
        worksheet.write(0, 1, "模块")
        worksheet.write(0, 2, "用例标题")
        worksheet.write(0, 3, "前置条件")
        worksheet.write(0, 4, "步骤")
        worksheet.write(0, 5, "预期")
        worksheet.write(0, 6, "验证状态截图")
        worksheet.write(0, 7, "用例状态")
        worksheet.write(0, 8, "测试类型")
        return worksheet



if __name__ == '__main__':
    test=AutoMaic()
    test.excelExcult()